<template>
  <el-tree
    ref="tree"
    :props="props"
    node-key="roleCode"
    :load="loadNode"
    lazy
    show-checkbox
    :check-strictly="true"
  ></el-tree>
</template>

<script>
import { list } from "@/api/role";
export default {
  data() {
    return {
      props: {
        label: "roleName",
        children: "children",
        isLeaf: function(data, node) {
          return !data.roleSon;
        }
      }
    };
  },
  methods: {
    loadNode(node, resolve) {
      if (node.level === 0) {
        return resolve([
          { roleCode: "0", roleName: "全部", roleSon: true, disabled: true }
        ]);
      } else {
        list({ roleFcode: node.data.roleCode }).then(res => {
          resolve(res.data);
        });
      }
    },
    getTreeRef() {
      return this.$refs.tree;
    }
  }
};
</script>